home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65c+IDA-1.4.4.1 / support / rename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-04  |  466 b   |  26 lines

  1. /*    @(#)rename.c    1.2    7/30/90    21:38:48    */
  2. #ifndef    lint
  3. static    char    sccs_id[] = "@(#)rename.c    1.2";
  4. #endif
  5.  
  6. #include    <unistd.h>
  7.  
  8. rename(old, new)
  9. char    *old,    *new;
  10. {
  11.     /* first make sure there's something to rename */
  12.     if (access(old, F_OK) < 0)
  13.         return(-1);
  14.  
  15.     /* get rid of any existing target file */
  16.     if (access(new, F_OK) == 0)
  17.         unlink(new);
  18.  
  19.     /* link the old to the new */
  20.     if (link(old, new) < 0)
  21.         return(-1);
  22.  
  23.     /* unlink the old name */
  24.     return(unlink(old));
  25. }
  26.